/**
 * python gen: Thu May 13 15:02:38 2021
 */
import { apiService } from "@/api/apiService.js";
export default {
  name: "zhxxbHome",
  data() {
    return {
      options: [
        {
          value: "1",
          label: "通过"
        },
        {
          value: "2",
          label: "不通过"
        },
        {
          value: "0",
          label: "未检查"
        }
      ],
      searchForm: {
        // name: "",
        CHECK_RESULT: ""
      },
      multipleSelection: [],
      tableData: [],
      currentPage: 1,
      totalCount: 0,
      PageSize: this.pageSizes[0],

      dialogFormVisible: false,
      ruleForm: {
        CHECK_ID: "",

        JGDM: "",

        NBJGH: "",

        JRXKZH: "",

        JGMC: "",

        KHYH: "",

        KHHJRXKZH: "",

        KHHJGDM: "",

        KHHLEI: "",

        ZHMC: "",

        ZH: "",

        ZHLX1: "",

        ZHLX2: "",

        KHRQ: "",

        XHRQ: "",

        ZHZT: "",

        BZ: "",

        CJRQ: ""
      },
      rules: {
        CHECK_ID: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        JGDM: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        NBJGH: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        JRXKZH: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        JGMC: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        KHYH: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        KHHJRXKZH: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        KHHJGDM: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        KHHLEI: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        ZHMC: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        ZH: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        ZHLX1: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        ZHLX2: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        KHRQ: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        XHRQ: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        ZHZT: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        BZ: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ],

        CJRQ: [
          // { required: true, message: "不能为空", trigger: "blur" }
        ]
      }
    };
  },
  mounted() {
    // do sth
    this.getList(true);
  },

  methods: {
    //todo

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize = val;
      // 注意：在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage = 1;
      this.getList(true);
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.currentPage = val;
      this.getList();
    },

    resetForm() {
      this.$refs["searchForm"].resetFields();
      this.getList();
    },
    getList(flag) {
      flag && (this.currentPage = 1);
      let params = {
        size: this.PageSize,
        page: this.currentPage - 1,
        ...this.searchForm
      };
      apiService.queryData(params, "ZHXXB").then(res => {
        let { totalElements, content } = res;
        this.totalCount = totalElements;
        this.tableData = content;
      });
    },

    // to 新增
    goAdd() {
      Object.keys(this.ruleForm).forEach(key => (this.ruleForm[key] = ""));
      this.dialogFormVisible = true;
      //   this.$refs["ruleForm"].resetFields();
      //   this.$router.push({ name: "ZHXXB-edit", params: { id: "" } });
      //   this.kjAddMenuTab({
      //     label: "详细信息",
      //     name: "ZHXXB-edit",
      //     path: "/kj/east/ZHXXB-edit",
      //     params: { id: "3333" },
      //   });
    },

    // to 编辑
    goUpdate() {
      let item = this.multipleSelection[0];
      this.ruleForm = JSON.parse(JSON.stringify(item));
      this.dialogFormVisible = true;
    },

    // 新增，修改 后， 点击[保存]
    doSave() {
      this.$refs["ruleForm"].validate(valid => {
        if (valid) {
          apiService.putItem(this.ruleForm, "ZHXXB").then(() => {
            this.dialogFormVisible = false;
            this.getList();
          });
        }
      });
    },

    // to delete
    goDelete() {
      this.$confirm("确定要删除数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.doDelete();
        })
        .catch(() => {});
    },

    doDelete() {
      let ids = this.multipleSelection.map(it => it.CHECK_ID);
      let params = { ids };
      apiService.deleteItem(params, "ZHXXB").then(() => {
        this.getList();
      });
    },

    // to check
    doCheck() {
      let ids = this.multipleSelection.map(it => it.CHECK_ID);
      let params = { ids };
      apiService.checkItem(params, "ZHXXB").then(() => {
        this.getList();
      });
    },

    // to import
    goImport() {},
    // to export
    goExport() {
      let params = {
        tableCode: "ZHXXB",
        desensitize: true
      };
      // apiService.exportItem(params);
      let baseUrl = process.env.VUE_APP_BASE_URL;
      window.open(
        `${baseUrl}/collect/packet/export?tableCode=${
          params.tableCode
        }&desensitize=${params.desensitize}`
      );
    }
  }
};
